package today.rocky.boot.eureka.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.netflix.ribbon.proxy.annotation.Hystrix;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.*;
import today.rocky.boot.eureka.service.EurekaService;

import java.util.Random;

/**
 * @author Rocky
 * @date 2020/2/25 16:26
 */
@RestController
@RequestMapping("/provider")
public class ProController {

    @Autowired
    private EurekaService service;

    private final static Random random = new Random();
    /**
     * 熔断错误回调方法
     */
    public String helloFallBack(){
        return "Error occurred!";
    }

    @GetMapping("/hello")
    public String getHello(){
        return service.sayHell()+",JY喜欢ZL,这是9111";
    }

    @GetMapping("/echo")
    public String echo(@RequestParam String message)throws Exception{
        // 如果随机时间 ⼤于 100 ，那么触发容错
        //fallback服务降级，调用另一个方法
        int value = random.nextInt(200);
        System.out.println("helloWorld() costs "+value+" ms.");
        try {
            Thread.sleep(value);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "qwertyuio"+message;
    }

}
